/*
 * File Name:               OverrideEditor.cs
 * 
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>

 * Create Date:             2017/04/12
 */

using System.Reflection;
using UnityEditor;
using UnityEngine;

public abstract class OverrideEditor : Editor
{
    readonly static BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;

    private Editor m_BaseEditor;
    protected Editor baseEditor
    {
        get { return m_BaseEditor ?? (m_BaseEditor = GetBaseEditor()); }
        set { m_BaseEditor = value; }
    }

    protected abstract Editor GetBaseEditor();

    
    protected override void OnHeaderGUI()
    {
        MethodInfo methodInfo = baseEditor.GetType().GetMethod("OnHeaderGUI", flags);
        if (methodInfo == null) return;
        methodInfo.Invoke(baseEditor, null);
    }

    public override void OnInspectorGUI()
    {
        baseEditor.OnInspectorGUI();
    }

    public override void DrawPreview(Rect previewArea)
    {
        baseEditor.DrawPreview(previewArea);
    }

    public override string GetInfoString()
    {
        return baseEditor.GetInfoString();
    }

    public override GUIContent GetPreviewTitle()
    {
        return baseEditor.GetPreviewTitle();
    }

    public override bool HasPreviewGUI()
    {
        return baseEditor.HasPreviewGUI();
    }

    public override void OnInteractivePreviewGUI(Rect r, GUIStyle background)
    {
        baseEditor.OnInteractivePreviewGUI(r, background);
    }

    public override void OnPreviewGUI(Rect r, GUIStyle background)
    {
        baseEditor.OnPreviewGUI(r, background);
    }

    public override void OnPreviewSettings()
    {
        baseEditor.OnPreviewSettings();
    }

    public override void ReloadPreviewInstances()
    {
        baseEditor.ReloadPreviewInstances();
    }

    public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
    {
        return baseEditor.RenderStaticPreview(assetPath, subAssets, width, height);
    }

    public override bool RequiresConstantRepaint()
    {
        return baseEditor.RequiresConstantRepaint();
    }

    public override bool UseDefaultMargins()
    {
        return baseEditor.UseDefaultMargins();
    }
}